# coding:utf-8

from typing import Dict
from views.template_page_view import BasePageTemplateView
from .common.translator import Translator
from common.utils.JsonReplace import JsonPlaceholderReplacer
from PyQt6.QtWidgets import (
    QHBoxLayout,
)


class StockRecommend(BasePageTemplateView):
    """Scroll interface"""

    def __init__(self, parent=None):
        t = Translator()
        super().__init__("StockRecommend", parent=parent)

    def doInitAndUpdate(self):
        self.addEchatTemplate(
            "板块得分",
            "stock_recommend",
            self.exchangeRecommendData,
            self.getBaseParam,
            1,
        )

    def getBaseParam(self) -> Dict[str, str]:
        return {"stockCode": "100001"}

    def exchangeRecommendData(self, jsonData: str, params: Dict[str, str]) -> str:
        source_data = [
            {
                "value": 99,
                "name": "半导体",
                "path": "10001",
                "children": [
                    {"value": 33, "name": "半导体1", "path": "Accounts/Access"},
                    {"value": 2, "name": "半导体2", "path": "Accounts/Authentication"},
                    {"value": 80, "name": "半导体3", "path": "Accounts/Notification"},
                ],
            },
            {
                "value": 15,
                "name": "金融证券",
                "path": "Accounts",
                "children": [
                    {"value": 76, "name": "国盛金控", "path": "Accounts/Access"},
                    {
                        "value": 92,
                        "name": "东方财富",
                        "path": "Accounts/Authentication",
                    },
                ],
            },
        ]
        replacer = JsonPlaceholderReplacer(jsonData)
        replacer.replace_placeholder("__STOCK_DATA__", source_data)
        replacer.replace_placeholder("__STOCK_NAME__", "板块推荐")

        return replacer.get_modified_json()
